home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / gpen32k / source / lib / osrc / tiffload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  1.6 KB  |  72 lines

  1. /************************************************************
  2. *   共通一般ライブラリー                                    *
  3. *        全モード対応 Tiff-Loader                            *
  4. *                                                            *
  5. *         0 : 正常終了                                        *
  6. *        -1 : エラー                                            *
  7. *        + : 画像モード違い    モードビット数                    *
  8. *                                                            *
  9. *                                        OKOME System 2        *
  10. ************************************************************/
  11.  
  12. #include    <stdio.h>
  13. #include    <string.h>
  14. #include    <EGB.H>
  15. #include    <tifflib.h>
  16. #include    <normlib.h>
  17.  
  18. static int xx, xx4, yy;
  19. static FILE *fp;
  20.  
  21. static int tlog(char *buf, int lof, int ls)
  22. {
  23.     egbput(xx,yy+lof,xx+xx4-1,yy+lof+ls-1,buf);
  24.     return (0);
  25. }
  26.  
  27. static int tlog2(char *buf, int lof, int ls)
  28. {
  29.     egbputc(xx,yy+lof,xx+xx4-1,yy+lof+ls-1,buf);
  30.     return (0);
  31. }
  32.  
  33. static int tfgs(char *buf, long sz)
  34. {
  35.     fread(buf, 1, sz, fp);
  36.     return (0);
  37. }
  38.  
  39. int tiffload(char *name, int xf, int yf)
  40. {
  41.     int x, y, comp, fill, cm, p, p0, p1;
  42.     long strip, clut;
  43.     char h[4096], ak[4096], tt[DECOMP_WORK_SIZE];
  44.     xx = xf;
  45.     yy = yf;
  46.     if ((fp=fopen(name,"rb"))==NULL)
  47.         return (-1);
  48.     fread(h,1,4096,fp);
  49.     if (TIFF_getHead(h,4096)==-1)
  50.     {
  51.         fclose(fp);
  52.         return (-1);
  53.     }
  54.     cm = TIFF_checkMode( &x, &y, &comp, &fill, &strip, &clut);
  55.     EGB_getResolution(&p0,&p1);
  56.     p = (EGB_getWritePage( 0,0 ) == 0) ? p0 : p1 ;
  57.     EGB_getModeInfo(p,NULL,NULL,NULL,NULL,&p0);
  58.     xx4 = x;
  59.     if (cm==1)
  60.         TIFF_setLoadFunc(tlog2,tfgs);
  61.     else if ((1<<cm)==p0 || (cm==16 && p0==32768))
  62.         TIFF_setLoadFunc(tlog,tfgs);
  63.     else {
  64.         fclose(fp);
  65.         return (cm);
  66.     }
  67.     p0 = (cm<8) ? (4096 / ((x + 7) / 8 * cm)) : (4096 * 8 / cm / x) ;
  68.     TIFF_loadImage( cm, x, y, strip, fill, comp, ak, x, p0, tt );
  69.     fclose(fp);
  70.     return (0);
  71. }
  72.